#include "stdafx.h"

Ogre::Matrix4 ivp=Ogre::Matrix4::IDENTITY;
Ogre::Matrix4 pvp=Ogre::Matrix4::IDENTITY;
Ogre::Real hurtEffect=0;
Ogre::Real du=0.2;

class PostProcessListener : public Ogre::CompositorInstance::Listener {
public:

	PostProcessListener(){
	}

	virtual void notifyMaterialSetup(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat) {
		if (pass_id == 1){	
			params1 = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();}
		else if (pass_id == 2){	
			params2 = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();}
		else if (pass_id == 3){
			params3 = mat->getTechnique(0)->getPass(0)->getVertexProgramParameters();}

	}

	virtual void notifyMaterialRender(Ogre::uint32 pass_id, Ogre::MaterialPtr &mat) {

		
		if (pass_id == 1)
			{params1->setNamedConstant("lightPosition", SunScreenSpacePosition); 
		mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("den",du);}
		else if (pass_id == 2)
		{params2->setNamedConstant("lightPosition", SunScreenSpacePosition);
		mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("den",du);}
		else if (pass_id == 3)
		{params3->setNamedConstant("lightPosition", SunScreenSpacePosition);
		mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("den",du);}

		if(pass_id==13)
			mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("den",hurtEffect);

		if(pass_id==14)
		{
			mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("invViewProjMatrix",ivp);
			mat->getTechnique(0)->getPass(0)->getFragmentProgramParameters()->setNamedConstant("prevViewProjMatrix",pvp);
		}
	}

	Ogre::Vector4 SunScreenSpacePosition;
private:
	Ogre::GpuProgramParametersSharedPtr params1;
	Ogre::GpuProgramParametersSharedPtr params2;
	Ogre::GpuProgramParametersSharedPtr params3;
	
};

PostProcessListener *postProcessListener;